//
//  GGZFBStartLevelView.m
//  Gunterapple
//
//  Created by 热带雨林 on 2020/4/2.
//  Copyright © 2020 热带雨林. All rights reserved.
//

#import "GGZFBStartLevelView.h"

@implementation GGZFBStartLevelView

- (instancetype)initWithFrame:(CGRect)frame{
    if(self = [super initWithFrame:frame]){
        [self setUpUI];
    }
    return self;
}
- (void)setUpUI{
    CGFloat wight = 14;
    CGFloat height = 14;
    for (NSInteger i= 0; i < 5; i ++) {
        UIImageView *startImg = [[UIImageView alloc]init];
        [self addSubview:startImg];
        startImg.image = [UIImage imageNamed:@"empty_star"];
        //此处是设置相对于父视图的位置与大小
        startImg.frame = CGRectMake(i * wight, 0, wight, height);
        //此处是设置自己的大小，不能设置位置
//        startImg.bounds = CGRectMake(i * wight, 0, wight, height);
    }
}
- (void)setLevel:(CGFloat)level{
    _level = level;
    //视图中的所有子视图都是执行setImage的方法
    [self.subviews makeObjectsPerformSelector:@selector(setImage:) withObject:[UIImage imageNamed:@"empty_star"]];
    NSInteger fullStart = (NSInteger)level;
    for (NSInteger i = 0; i < fullStart; i ++) {
        UIImageView *startImgView = self.subviews[i];
        startImgView.image = [UIImage imageNamed:@"full_star"];
    }
    //设置半🌟
    if(level - fullStart > 0){
        UIImageView *halfStart = self.subviews[fullStart];
        halfStart.image = [UIImage imageNamed:@"half_star"];
    }
}
@end
